package entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.appengine.api.datastore.Key;

@XmlRootElement
@Entity
public class Narudzbina {
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key id;
	
	private Date datum;
	
	private Kupac kupac;
	
	@ManyToOne(fetch=FetchType.EAGER)
	public Kupac getKupac() {
		return kupac;
	}

	public void setKupac(Kupac kupac) {
		this.kupac = kupac;
	}
	
	private NacinPlacanja nacinPlacanja;
	
	
	@OneToOne(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	public NacinPlacanja getNacinPlacanja() {
		return nacinPlacanja;
	}

	public void setNacinPlacanja(NacinPlacanja nacinPlacanja) {
		this.nacinPlacanja = nacinPlacanja;
	}
	
	private List<Proizvod> proizvodiNarudzbina=new ArrayList<Proizvod>();
	
	@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	public List<Proizvod> getProizvodiNarudzbina() {
		return proizvodiNarudzbina;
	}

	public void setProizvodiNarudzbina(List<Proizvod> proizvodiNarudzbina) {
		this.proizvodiNarudzbina = proizvodiNarudzbina;
	}

	public Narudzbina()
	{
		datum=new Date();
	}
	
	public Date getDatum() {
		return datum;
	}

	public void setDatum(Date datum) {
		this.datum = datum;
	}
	
	public void dodajProizvodiNarudzbina(Proizvod proizvod)
	{
		if(proizvodiNarudzbina==null)
			proizvodiNarudzbina=new ArrayList<Proizvod>();
		proizvodiNarudzbina.add(proizvod);
	}
}
